#  Copyright (c) 2021
#  User:SDUFE-Zhaocheng Lu
#  File:lib.py
#  Date:2021/08/16 23:30:16
import pymysql


class SQL:
    config = {
        'host': '118.190.60.13',
        'user': 'YQ_Sign',
        'password': '5BnJECbLeXJCmyZj',
        'database': 'yq_sign',
    }

    def __init__(self):
        self.db = pymysql.connect(host=self.config['host'], user=self.config['user'],
                                  password=self.config['password'],
                                  database=self.config['database'])
        self.cursor = self.db.cursor()

    def run(self, sql: str):
        self.cursor.execute(sql)

    def select(self, field_list: list, table, check_field):
        sql = "select " + ','.join(field_list) + ' from ' + table + (' where ' if len(
            check_field) > 0 else '') + (check_field.replace('&', ' and ').replace('|', ' or ') if len(
            check_field) > 0 else '')
        self.run(sql)
        return self.cursor.fetchall()


field_name = ['school_id', 'password', 'email', 'name', 'sex', 'study_id', 'college_id', 'address', 'contact', 'phone',
              'province_id', 'city_id', 'now_address','addTime','expireTime']
data_field = ['name', 'sex', 'study_id', 'college_id', 'address', 'contact', 'phone',
              'province_id', 'city_id', 'now_address']
qd_field = ['name', 'sex', 'study_id', 'college_id', 'address', 'contact', 'phone', 'province_id', 'city_id',
            'now_address', 'verify']
fail_times = 3
success_list = []
error_list = []
pass_list = []
